//
//  OMAppDelegate.m
//  Weibbo
//
//  Created by ifuninfo on 13-6-7.
//  Copyright (c) 2013年 Omnivores. All rights reserved.
//

#import "OMAppDelegate.h"
#import <TencentOpenAPI/TencentOAuth.h>
#import "DraftItem.h"

@implementation OMAppDelegate
@synthesize rootNavigationController  = _rootNavigationController;
@synthesize homeController            = _homeController;

- (void)dealloc
{
    UIRelease(_rootNavigationController);
    UIRelease(_homeController);
    UIRelease(_window);
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    _homeController = [[OMHomeViewController alloc] initWithNibName:@"OMHomeViewController" bundle:nil];
    
    _rootNavigationController = [[UINavigationController alloc] initWithRootViewController:_homeController];
    
    [_rootNavigationController setNavigationBarHidden:YES animated:NO];
    
    
    [self.window setRootViewController:_rootNavigationController];
    self.window.backgroundColor = [UIColor clearColor];
    [self.window makeKeyAndVisible];
    
    
//    NSMutableAttributedString  *string = [[NSMutableAttributedString alloc] initWithString:@"这就是汤姆的创业理论，在不久前的接受视频采访时，他将编程和软件开发比喻成“吸毒嗑药”（原文为 Chasing the Dragons，的状态，并且透露了他创立 Gravatar 和 GitHub 的故事。"];
//    [string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, [string length])];
//    NSShadow  *shadow = [[NSShadow alloc] init];
//    [shadow setShadowBlurRadius:2.0f];
//    [shadow setShadowColor:UIRedColor];
//    [shadow setShadowOffset:CGSizeMake(1, 1)];
//    [string addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(0, [string length])];
//    
//    [string addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0, 10)];
//    DraftItem  *item = [[DraftItem alloc] init];
//    [item setText:string];
//    
//    NSLog(@"%@",[[item toDictionary] objectForKey:@"text"]);
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    if ([SinaWeiboSDK HandleOpenURL:url]) {
        return [SinaWeiboSDK HandleOpenURL:url];
    }
    if ([TencentOAuth HandleOpenURL:url])
    {
        return [TencentOAuth HandleOpenURL:url];
    }
    return NO;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [WBBData save];
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
